#!/bin/sh

echo "Now we are installing TERN, please make sure your llvm is 2.7 released version, and your \$DEFENS_ROOT setting is correct."
echo "Please make sure you current directory is $DEFENS_ROOT/rcs-modules/klee/."

# build idm, sync-func, omit-branch.
cd ../../idm
make clean
make ENABLE_OPTIMIZED=0

cd ../rcs-modules/klee/llvm-instrument/sync-func
make clean
make ENABLE_OPTIMIZED=0

cd ../omit-branch
make clean
make ENABLE_OPTIMIZED=0

cd ../../
cd llvm-instrument/trace-sync-events
make clean
make ENABLE_OPTIMIZED=0
cd stub
rm -rf template.bc
make LLVMGCC=llvm-gcc template.bc
cd ../../../


# build klee-uclibc.
cd klee-uclibc
./configure --with-llvm=$DEFENS_ROOT/
make LLVMGCC=llvm-gcc clean
CPU=`uname -m`
if [ "$CPU" = "x86_64" ]
then
	cp src-64bit/.config .
	cp src-64bit/kernel_types.h libc/sysdeps/linux/x86_64/bits/
fi
make LLVMGCC=llvm-gcc
cd ..


# build klee.
CFLAGS="-Wno-variadic-macros" CXXFLAGS="-Wno-variadic-macros" ./configure --with-llvmsrc=$DEFENS_ROOT/llvm-2.7/ --with-llvmobj=$DEFENS_ROOT/llvm-obj --with-runtime=Debug \
--with-uclibc=$DEFENS_ROOT/rcs-modules/klee/klee-uclibc
mkdir Debug
mkdir Debug/lib
cp $BUGS_DIR/bugs/splash2/splash2/mpc-0.5.2/install/lib/* Debug/lib/
cp ../../llvm-obj/Debug/lib/idm.so Debug/lib/libidm.so
cp ../../llvm-obj/Debug/lib/libsync-func.a Debug/lib/
cp ../../llvm-obj/Debug/lib/libomit-branch.a Debug/lib/
#make clean
make ENABLE_OPTIMIZED=0

echo "\n\nI suggest you append $DEFENS_ROOT/rcs-modules/klee/Debug/bin to your PATH env var."

